public class Solution {
    public static int NumberOf1Between1AndN_Solution(int n) {
        int ncopy = n;
        //从低到高计算不同位上的1的个数。
        int low;
        int number;
        int high;
        int count=0;
        int factor = 1;
        while(n/(factor)!=0){
            number = n/(factor)%10; //当前位
            high = n/(factor*10);//高位,所有高位
            if(factor==1)
                low = 0;
            else low = n%factor;//低位，所有低位
            if(number==0)
                count += high*(factor);//高位
            else if(number==1){
                count += high*(factor) + low + 1;//高位乘 + 低位+1
            }else{
                count += (high+1)*(factor);//（高位+1）*
            }
            factor *= 10;
        }
        return count;
    }
    public static void main(String args[]){
        int k=2;
        int[] a={6,-3,-2,7,-15,1,2,2};
        int b = NumberOf1Between1AndN_Solution(10000);
        System.out.println(b);
    }

}

